const channel=new BroadcastChannel("timer_channel");
var index=0;
var timer=null;
channel.onmessage=function(event){
    console.log("worker 收到消息：",event.data);
    if(event.data==="start"){
        timer=setInterval(()=>{
            channel.postMessage({msg:"计时器已经开始",data:++index});
        },1000)
    }else if(event.data==="stop"){
        clearInterval(timer)
        channel.postMessage({msg:"计时器已经停止",data:index})
    }
};


channel.postMessage("wroker 已经准备好接受信息")